package com.dd.framework.security.component;

import com.alibaba.fastjson.JSONObject;
import com.dd.common.entity.CommonResult;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 * 用户认证失败处理
 */
public class MallAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {

        response.setStatus(402);
        response.getWriter().write(JSONObject.toJSONString(CommonResult.loginFail("")));
    }
}
